$(function () {
    $("button").click(function () {
        var $this = $(this);
        if($this.attr('type')=="refresh"){
            var flag = confirm("确定刷新?");
            if (!flag){
                return;
            }
        }
        var a ;
        $.get('/control', {
            id: $this.attr('value'),
            url: $this.attr('url'),
            type: $this.attr('type'),
            title:$this.attr('title'),
            author:$this.attr('author'),
            m :$this.attr("m"),
            dept:$this.attr("dept"),
            users:$this.attr("users"),
            game:$this.attr("game")
        }, function (data) {
            console.log(data);
            var text = $this.html();
            $this.html(data);
            $this.css({
                "color":"red"
            })
            a = setTimeout(function(){
                $this.html(text);
            },2000)
        })
    });

    $("a.safea").click(function(){
        var $this = $(this);
        if($this.attr("ended")){
            return false;
        }
        var count = $this.attr("count");
        var rank = $this.attr("rank");
        var switchKey = $this.attr("switchKey");
        var url = $this.attr("url")
        //开始抽奖
        if(switchKey=="1"){
            $.post(command.cloudeServer+url,{
                switchKey:1,
                rank:parseInt(rank),
                count:parseInt(count)
            },function(){
                $this.attr("ended");
                $this.css({
                    color:"red"
                })
            });
        }else if(switchKey=="0"){
            console.log(command.cloudeServer+url)
            $.post(command.cloudeServer+url,{
                switchKey:0
            },function(){
                $this.attr("ended");
                $this.css({
                    color:"red"
                })
                console.log(111)
            });
        }
    });
    $("a.initD").click(function(){
        var $this = $(this);
        var pwd = $this.attr("pwd");
        var url = $this.attr("url");
        $.post(command.cloudeServer+url,{
            pwd:pwd
        },function(data){

            console.log(data)
        });
    });
});